import { createStore, compose, applyMiddleware } from 'redux'
import thunkMiddleware from 'redux-thunk'
import {createLogger} from 'redux-logger'
import createHistory from 'history/createBrowserHistory'

import { routerMiddleware } from 'react-router-redux'

import reducer from  '../reducers'
const loggerMiddleware = createLogger({ predicate: (getState, action) => __DEV__});
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const history = createHistory()
const historyMiddleware = routerMiddleware(history)

export default ( initialState ) => {
	const enhancer = composeEnhancers(
		applyMiddleware(
			thunkMiddleware,
			historyMiddleware
		)
	)
	return createStore(reducer, initialState, enhancer)
}